package com.interest.controller.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.interest.base.entity.ModelBean;
import com.interest.modules.movie.entity.Movie;
import com.interest.modules.movie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangfeng on 16-12-5.
 */
@Controller
@RequestMapping("/api/movie")
public class ApiMovieController {
    @Autowired
    private MovieService movieService;

    @RequestMapping("/list")
    @ResponseBody
    public ModelBean getList() {
        List<Movie> movies = movieService.getMovie();
        JSONObject data = new JSONObject();
        data.put("list", JSONArray.parse(JSON.toJSONString(movies)));
        return new ModelBean(data);
    }

    @RequestMapping("/random")
    @ResponseBody
    public ModelBean random() {
        Movie movie = movieService.getRandom();
        JSONObject data = new JSONObject();
        data.put("result", movie);
        return new ModelBean(data);
    }
}
